import html2canvas from './html2canvas.min'

// 截图 用
export async function toImage(domBox){
  // 手动创建一个 canvas 标签
  const canvas = document.createElement('canvas')
  // 获取父标签，意思是这个标签内的 DOM 元素生成图片
  let canvasBox = domBox
  // 获取父级的宽高
  const width = parseInt(window.getComputedStyle(canvasBox).width)
  const height = parseInt(window.getComputedStyle(canvasBox).height)
  // 宽高 * 2 并放大 2 倍 是为了防止图片模糊
  canvas.width = width
  canvas.height = height
  canvas.style.width = width + 'px'
  canvas.style.height = height + 'px'
  const context = canvas.getContext('2d')
  context.scale(2, 2)
  const res = await html2canvas(canvasBox, { useCORS: false });
  // document.body.appendChild(canvas)  //页面布局会乱  测试用
  return res.toDataURL('image/png')
}

export default {

}
